#include "ui/MainFrame.h"
#include <QApplication>
#include <QMessageBox>
#include <QDir>
#include <QDebug>

#include "ZimingxiayiContext.h"

#ifdef QT_DEBUG
//#include "vld.h"
#endif

#include <Core/Log/Logger.h>
#include <Core/Log/BoostLogger.h>

#include <memory>

using namespace jet;

int main(int argc, char *argv[])
{
    std::unique_ptr<BoostLogger> logger;

    QApplication a(argc, argv);

    QString log_folder = QCoreApplication::applicationDirPath() + "/Log";
    QDir dir(log_folder);
    if(!dir.exists()) dir.mkpath(log_folder);

    // 配置文件
    // 日志
    logger.reset(new BoostLogger(LOG_LEVEL_INFO));
    logger->Initialize();
    logger->AddLogFilter(log_folder.toStdString(), "zimingxiayi");
    Logger::SetGlobalLogger(logger.get());

    JET_STRING log_level = L"INFO";
    // Start Magic.
    Logger::LogFixed("-----------------------------------------------");
    Logger::LogFixed("Starting zimingxiayi...");
    Logger::LogFixed(QString("Log Level = %1").arg(QString::fromStdWString(log_level)));

    // 创建上下文
    ZimingxiayiContext *context = CreateContext();
    ZimingxiayiContext::SetContext(context);//设置全局上下文

    MainFrame w;
    w.show();
    ZimingxiayiContext::Context()->Initialize(); //初始化

    return a.exec();
}
